<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!doctype html>
<html>
	<head>
		<title>管理员登录列表</title>
		<base href="<%=basePath%>" />
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<meta name="renderer" content="webkit">
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<meta name="apple-mobile-web-app-title" content="Amaze UI" />
		<link rel="stylesheet" href="layui/css/layui.css" media="all"> <!-- 适应所有设备 -->
		<style type="text/css">
		</style>
	</head>
	<% String nowDay = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); %>
	<body>
    <br/>
	<table class="layui-hide" id="querylist" lay-filter="querylist"></table>
	    
	    <script type="text/html" id="modify">
          <a class="layui-btn  layui-btn-xs" lay-event="remove">强制下线</a>
        </script>
	    
	    <script src="js/jquery.min.js"></script>
		<script src="layui/layui.js"></script>
		<script>
		    layui.use(['layer','form','table'],function(){
		    	var layer = layui.layer,
		    	    form  = layui.form,
		    	    table = layui.table,
		    	    laydate = layui.laydate;
		    	
		    	 layer.config({
						extend: 'MySkin/style.css'
					});
		    	table.render({
		    		elem:'#querylist',
		    		url:'loginquery/list',
		    		toolbar: '#toolbar', //开启头部工具栏，并为其绑定左侧模板
		    		defaultToolbar: [],  //隐藏右边工具栏
		    		method:'post',
		    		title:'管理员列表	',
		    		skin: 'row',
		    		id:'AllTable',
		    		cellMinWidth : 40,
		    		request:{
		    			pageName:'PageIndex',
		    			limitName:'PageCount'
		    		},
		    		cols:[[
		    			{field:'id',title:'ID',style:'color:red',hide:true},
		    			{field:'loginIP',title:'登录IP',style:'color:blue'},
		    			{field:'loginTime',title:'登陆时间',style:'color:red'},
		    			{field:'adminName',title:'登录名称',style:'color:blue'},
		    			{field:'sessionID',title:'sessionID',style:'color:blue'},
		    			{fixed:'right',title:'操作',toolbar:'#modify'}
		    			]],
		    			page : true,//分页
						response : {
							statusCode : 200
						//重新规定成功的状态码为 200，table 组件默认为 0
						},
						parseData : function(res) { //将原始数据解析成 table 组件所规定的数据
							return {
								"code" : res.status, //解析接口状态
								"msg" : res.message, //解析提示文本
								"count" : res.count, //解析数据长度
								"data" : res.data
							//解析数据列表
							};
						}
		    	});
		    	
		    	
		    	//监听行工具事件
		    	table.on('tool(querylist)',function(obj){
		    		var data = obj.data;
		    		var id = data.id;
		    		var IP = data.loginIP;
		    		if(obj.event === 'remove'){
		    			$.ajax({
		    				type:"POST",
		    			    url:'loginquery/remove',
		    			    data:{id:id,IP:IP},
		    			    async: true,
		    			    // type:"json", //返回的数据是json
		    				success:function(resp){
		    					if(resp === 'success'){
		    						layer.msg("下线成功",{icon:1});
		    						setTimeout(function(){
		    							table.reload('AllTable', {});
		    						},1000);
		    					}
	    				    },
	    				    error:function(){
	    				    	layer.msg("查询失败",{icon:2});
	    				    }
		    		    });
		    		}
		    	});
		    	
		    	setTimeout(function(){
					  table.reload('AllTable', {});
				  },60000);
		    });
		</script>
    </body>
</html>